
const baseUrl = "https://community.qiyeji.com"
export default ({
  url,data={},loadingTop,loadingCenter=true,id,method="GET",header={'content-type': 'application/x-www-form-urlencoded'}
})=>new Promise( async (resolve,reject)=>{
  //显示loading
  if (loadingTop){
    uni.showNavigationBarLoading()
    uni.setNavigationBarTitle({
      title: '加载中',
    })
  }else if(loadingCenter){
    uni.showLoading({
      title: '加载中',
    })
  }
  //数据读取
	console.log(url)
	console.log(data)
	console.log(method)
	console.log(header)
	var token = ""
		await uni.getStorage({
			key:"token",
			success(e){
				token=e.data
			}
		})
	setTimeout(()=>{
	header = token ? {Authorization:token}:header
	uni.request({
    url: baseUrl + url,
    data,
    method,
	header,
    success:function(res){
      if (loadingTop) uni.hideNavigationBarLoading()
      else uni.hideLoading()
	  if(res.data.code==500400){
		  uni.redirectTo({
		  	url:"/pages/login/login",
			success() {
				uni.showToast({
					icon:"none",
							title:res.data.msg,
							duration:2000
				})
			}
		  })
		  return 
	  }
      resolve(res)
    },
    fail:function(err){
      if(loadingTop) uni.hideNavigationBarLoading()
      else uni.hideLoading()
      reject(err)
    },
    complete:function(){
      if (loadingTop) uni.hideNavigationBarLoading()
      else uni.hideLoading()
    }
  })
	},100)
	
  

})